<?php

namespace App\Traits;

trait BaseResource {
	/**
	 * @var array
	 */
	protected $withoutFields = [], $stamp = "default";

	public function toArray($request) {
		return $this->{'to' . ucfirst($this->stamp)}($request);
	}

	/**
	 * Set the keys that are supposed to be filtered out.
	 *
	 * @param array $fields
	 * @return $this
	 */
	public function hide(array $fields) {
		$this->withoutFields = $fields;
		return $this;
	}

	public function type(string $type) {
		$this->stamp = $type;
		return $this;
	}
	/**
	 * Remove the filtered keys.
	 *
	 * @param $array
	 * @return array
	 */
	protected function filterFields($array) {
		return collect($array)->forget($this->withoutFields)->toArray();
	}
}